package com.Tokiu.Aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAdvice {

//    @Pointcut("execution(void com.Tokiu.Dao.BaoDao.save())")
    @Pointcut("execution(void com.*.*.*.save())")
    private void pt(){}

    @Pointcut("execution(* com.Tokiu.Service.*.*(..))")
    private void Servicept(){}


    @Before("pt()")
    public void method(){
        System.out.println(System.currentTimeMillis());
    }

    @Around("Servicept()")
    public Object method2(ProceedingJoinPoint pjp) throws Throwable {
        //获取执行签名信息
        Signature signature = pjp.getSignature();
        //通过签名获取执行类型（接口名）
        Class ClassName = signature.getDeclaringType();
        //通过签名获取执行操作名称（方法名）
        String MethodName = signature.getName();

        Long start=System.currentTimeMillis();
        Object proceed = pjp.proceed();
        Long end=System.currentTimeMillis();

        System.out.println(ClassName+"."+MethodName+"---->"+(end-start)+"ms");
        return proceed;

    }
}
